package com.ruoyi.mobile.utils;

import java.io.Serializable;
import java.util.List;

public class Paginator<T> implements Serializable {
    /** serialVersionUID */
    private static final long serialVersionUID  = -6231408155509180106L;

    /** 默认页码 */
    public static final long   DEFAULT_PAGE_NO   = 1;
    /** 默认每页条数 */
    public static final long   DEFAULT_PAGE_SIZE = 10;

    /** 当前页码 */
    private long               pageNo;

    /** 每页条数 */
    private long               pageSize;

    /** 总条数 */
    private long              totalDataNum;

    /** 总页数 */
    private long               totalPageNum;

    /** 当前页数据 */
    private List<T> pageData;

    /**
     * 构造函数
     *
     */
    public Paginator() {
        pageNo = DEFAULT_PAGE_NO;
        pageSize = DEFAULT_PAGE_SIZE;
        totalDataNum = 0;
        totalPageNum = 0;
    }

    /**
     * 构造函数
     *
     * @param pageNo
     * @param pageSize
     * @param totalDataNum
     */
    public Paginator(long pageNo, long pageSize, long totalDataNum) {
        this.pageNo = pageNo;
        this.pageSize = pageSize == 0 ? DEFAULT_PAGE_SIZE : pageSize;
        this.totalDataNum = totalDataNum;
        this.totalPageNum = (int) ((totalDataNum + pageSize - 1) / pageSize);
    }

    /**
     * 构造函数
     *
     * @param pageNo
     * @param pageSize
     * @param totalDataNum
     * @param pageData
     */
    public Paginator(long pageNo, long pageSize, long totalDataNum, List<T> pageData) {
        this.pageNo = pageNo;
        this.pageSize = pageSize == 0 ? DEFAULT_PAGE_SIZE : pageSize;
        this.totalDataNum = totalDataNum;
        this.totalPageNum = (int) ((totalDataNum + pageSize - 1) / pageSize);
        this.pageData = pageData;
    }

    public long getPageNo() {
        return pageNo;
    }

    public void setPageNo(long pageNo) {
        this.pageNo = pageNo;
    }

    public long getPageSize() {
        return pageSize;
    }

    public void setPageSize(long pageSize) {
        this.pageSize = pageSize == 0 ? DEFAULT_PAGE_SIZE : pageSize;
        this.totalPageNum = (int) ((totalDataNum + pageSize - 1) / pageSize);
    }

    public long getTotalDataNum() {
        return totalDataNum;
    }

    public void setTotalDataNum(long totalDataNum) {
        this.totalDataNum = totalDataNum;
        pageSize = this.pageSize == 0 ? DEFAULT_PAGE_SIZE : this.pageSize;
        this.totalPageNum = (totalDataNum + pageSize - 1) / pageSize;
    }

    public long getTotalPageNum() {
        return totalPageNum;
    }

    public List<T> getPageData() {
        return pageData;
    }

    public void setPageData(List<T> pageData) {
        this.pageData = pageData;
    }

    public void setTotalPageNum(long totalPageNum) {
        this.totalPageNum = totalPageNum;
    }
}
